/**
 * Created by Administrator on 2016/8/1.
 */

var uuid = require('node-uuid');
var logger = require('../../utils/logHelper').helper;
var mineService = require('../service/mineService');

/**
 * @param req
 * @param res
 */

//我的头像信息
exports.mineproinfo = function(req, res) {
    var userid=req.query.userid;
    mineService.mineproinfo(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};

//个人公司信息
exports.mineprofile = function(req, res) {
    var userid=req.query.userid;
    mineService.mineprofile(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};

//我的订单
exports.mineorder = function(req, res) {
    var userid=req.query.userid;
    mineService.mineorder(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};

//我的意见
exports.mineopinion = function(req, res) {
    var id = uuid.unparse(uuid.v4(null, new Buffer(32), 0));
    var userid=req.body.userid;
    var opitype=req.body.array;
    var opinion = req.body.opinion;
    var createAt = new Date();
    console.log(opitype);
        opitype=opitype.join(",");
    var params ={
        id:id,
        userid:userid,
        opitype:opitype,
        opinion:opinion,
        createAt:createAt,
        status:1
    }
    mineService.mineopinion(params,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};


//管理员待处理订单
exports.adminpending = function(req, res) {
    var userid=req.query.userid;
    mineService.adminpending(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};

//待处理订单
exports.pendingorder = function(req, res) {
    var id=req.query.id;
    var userid=req.query.userid;
    mineService.pendingorder(userid,id,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};


//删除订单
exports.deleteorder = function(req, res) {
    var id=req.body.id;
    var userid=req.body.userid;
    mineService.deleteorder(id,userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};

//我的消费
exports.mineexpend = function(req, res) {
    var userid=req.query.userid;
    mineService.mineexpend(userid,function(err, rows) {
        if(err)
        {
            res.send({success:false,msg:"查询失败"});
        }else{
            res.send({success:true,data:rows});
        }
    });
};